#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int t, n, m;
int vis[100007];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> t;
    while(t--){
       cin >> n >> m;
        memset(vis, 0, sizeof(vis));
       for(int i = 0; i < m; i++){
           int a, b, c;
           cin >> a >> b >> c;
           vis[b] = 1;
       }
        int root1;
        for(int i = 1; i <= n; i++){
            if(!vis[i]){
                root1 = i;
            }
        }
        for(int i = 1; i <= n; i++){
            if(i == root1) continue;
            cout << root1 << " " << i << endl;
        }
    }
}
